<?php
/**
 * Class for plugins type of <i>Psa_Plugin_Model</i>.
 * 
 * LICENSE:
 * 
 * This library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with This library. If not, see <{@link http://www.gnu.org/licenses/}>.
 *
 * @link http://code.google.com/p/phpstartapp/
 * @author Bojan Mauser <bmauser@gmail.com>
 * @copyright Bojan Mauser 2009
 * @package psa
 * @subpackage plugins
 * @version $Id: Psa_Plugin_Model.class.php 464 2009-03-24 00:30:12Z bmauser $
 */


/**
 * Class for plugins type of <i>Psa_Plugin_Model</i>.
 * Model plugins (classes that extends Psa_Plugin_Model class) are place for logic of your application.
 * In model you do all calculations, get and store data to a database and all other business (domain) logic
 * of your application.
 * 
 * Model classes have methods that are called from controller. You should organize your model methods 
 * into more model classes to be logically grouped. You can also put classes for each group of operations into
 * different subfolders. Don't make one big model class with all methods your application needs.
 * 
 * You should put results from model into {@link psa_result} object because model and view communicate through
 * psa_result object.
 * 
 * You can write <i>Psa_Plugin_Model</i> plugins by extending this class. Here is an example:
 * 
 * <code>
 * <?php
 * class my_plugin extends Psa_Plugin_Model{
 * 	
 *	// Maximum number in result from functions below
 *	var $max_number = 150;
 *
 *	// Puts even numbers till $to_number in $psa_result object.
 *	function even_numbers($to_number){
 *		
 *		for($i=0; $i <= $this->max_number; $i++){
 *			if($i % 2 == 0)
 *				$return[] = $i;
 *		}
 * 		// put results into psa_result object
 *		$this->psa_result->even_numbers = $return;
 *	}
 * }
 * ?>
 * </code>
 * 
 * @see Psa_Plugin_Controller
 * @see Psa_Plugin_View
 */
class Psa_Plugin_Model{
	
	/**
	 * Reference to result object
	 * @var Psa_Result
	 */
	protected $psa_result;
	
	
	/**
	 * Reference to registry object
	 * @var Psa_Registry
	 */
	protected $psa_registry;
	
	
	/**
	 * Reference to database connect object
	 * @var Psa_Pdo
	 */
	protected $psa_database;
	
	
	/**
	 * Constructor. Sets the $psa_result member variable.
	 * @param $psa_result reference to global result object
	 */
	function __construct(){
		
		// global database connect object
		global $psa_database;
		
		// reference to database object
		$this->psa_database = $psa_database;
		
		// set reference to result object
		$this->psa_result = Psa_Result::get_instance();
		
		// set reference to registry object
		$this->psa_registry = Psa_Registry::get_instance();
	}
}

